package com.hmall.api.item.fallback;

import com.hmall.api.item.ItemClient;
import com.hmall.api.item.dto.ItemDTO;
import com.hmall.api.item.dto.OrderDetailDTO;
import com.hmall.common.utils.CollUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;

/**
 * 商品服务的出现异常的降级类,降级策略
 *
 * @Author mr.zhang
 * Date 2025/6/18 10:33
 */
@Component
@Slf4j
public class ItemClientFallbackFactory  implements FallbackFactory<ItemClient>{
    @Override
    public ItemClient create(Throwable cause) {
        return new ItemClient() {
            @Override
            public List<ItemDTO> queryItemByIds(Collection<Long> ids) {
                log.error("调用ItemClient的queryItemByIds出现错误,参数,原因{}",ids,cause);
                return CollUtils.emptyList();
            }

            @Override
            public void deductStock(List<OrderDetailDTO> items) {
                log.error("调用ItemClient的deductStock出现错误,参数{},原因{}",items,cause);
            }
        };
    }
}
